struct fColorRect {
 word  pCount;  /* 2 or 7 */
 Point Loc;
 word Color,
  Row,
  Col,
  Mode;
 long resID;
 word resFileID;
};
typedef struct fColorRec fColorRec; *fColorRecPtr;



/* Picture elements should be defined in 640 mode using a suitable paint
   program.  Elements should have a leading whitespace on the top/left
   edges equal to 1 row and 2 pixel columns (appears as 1 column in 640).
   The total width/2 should be an multiple of the Col value (e.g. if Col
   is 5, width of 100 and 240 are ok because (100/2)%5=0 and (240/2)%5 = 0,
   but 302 isn't because (302/2)%5=1).  Total height should be a multiple
   of the Row value.  A palette picture is an Col by Row array of picture
   elements:

 element  palette (4 Col by 2 Row)
 -------  ------------------------
 wwwwwww  wwwwwwwwwwwwwwwwwwwwwwwwwwww
 wXXXXXX  wXXXXXXwXXXXXXwXXXXXXwXXXXXX
 wXXXXXX  wX e0 XwX e1 XwX e2 XwX e3 X
 wXXXXXX  wXXXXXXwXXXXXXwXXXXXXwXXXXXX
   (v4,h14) wwwwwwwwwwwwwwwwwwwwwwwwwwww
   wXXXXXXwXXXXXXwXXXXXXwXXXXXX
   wX e4 XwX e5 XwX e6 XwX e7 X
   wXXXXXXwXXXXXXwXXXXXXwXXXXXX
      (v8,h56)

*/
word remColorPalette(fColorRecPtr p)
{
word   retVal, mHit, done, Row, Col, lastRow, lastCol, hDelta, vDelta;
Rect  *trans, item;
long  curFile;
GrafPortPtr winP, oldP;
Point  mLoc;

 if (p->pCount == 2) { /* mutate old call to new form */
  p->pCount = 7; 
  p->Row = p->Col = 4;
  p->Mode = 0;
  p->resID = 2L;
  p->resFileID = fResID;
 }

 if (p->pCount != 7)
  return SetToolError(invalidPCount);

 curFile = SetResFile2(p->resFileID, 1);
 PalettePic = LoadResource(rPicture, p->resID);
 retVal = toolerror();
 SetResFile1(curFile);
 if (retVal)
  return SetToolError(retVal);

 (byte *) trans = (byte *) deref(PalettePic) + 2L);

 PaletteR1.v1 = 0;   /* window rect */
 PaletteR1.h1 = 0;
 PaletteR1.v2 = trans->v2 + 4;
 PaletteR1.h2 = trans->h2 + vMode ? 8 : 4; 

 PaletteR2.v1 = 2;   /* control rect */
 PaletteR2.h1 = vMode ? 4 : 2;
 PaletteR2.v2 = trans->v2 + 2;
 PaletteR2.h2 = Palette.h1 + trans->h;   

 if (p->Loc.v < 15)
  p->Loc.v = 15;
 else if (p->Loc.v > (195 - PaletteR1.v2))
  p->Loc.v = 195 - PaletteR1.v2;

 if (vMode) {
  if (p->Loc.h < 10)
   p->Loc.h = 10;
  else if (p->Loc.h > (630 - PaletteR1.h2))
   p->Loc.h = 630 - PaletteR1.h2;
 }
 else {
                if (p->Loc.h < 5)
                        p->Loc.h = 5;
                else if (p->Loc.h > (315 - PaletteR1.h2))
                        p->Loc.h = 315 - PaletteR1.h2;
 }







void twiddleRect(RectPtr rect, word mode)
{
 
 if (mode == 1)
  InvertRect(rect);
 else {
   SetSolidPenPat(mode);
  FrameRect(rect);
 }
}

void setupRect(RectPtr rect, word col, word row, word hdelta, word vdelta)
{

 rect->v1 = (row * vdelta) + 2;
 rect->v2 = rect->v1 + vdelta + 1;
 rect->h1 = (col * hdelta) + vMode ? 4 : 2;
 rect->h2 = rect->h1 + hdelta + vMode ? 2 : 1;
}
